package recursion;

import java.io.File;

public class RecursionDemo05 {
    public static void main(String[] args) {
        File dirOrFile = new File("day21-file/abc");
        if (dirOrFile.exists()) {
            boolean result = deleteDirOrFile(dirOrFile);
            if (result) {
                System.out.println(dirOrFile + "删除成功");
            } else {
                System.out.println(dirOrFile + "删除失败");
            }
        } else {
            System.out.println(dirOrFile + "指定路径不存在");
        }
    }


    /**
     *
     * @param DirOrFile 传入一个文件夹
     * @return
     */
    public static boolean deleteDirOrFile(File DirOrFile){
        if (DirOrFile.isDirectory()) {
            File[] files = DirOrFile.listFiles();
            if (files != null) {
                for (File file : files) {
                    deleteDirOrFile(file);
                }
            }
        }
        return DirOrFile.delete();
    }
}
